/*
 * @Description:
 * @Version: 1.0
 * @Author: wenbin
 * @Date: 2021-11-15 14:27:20
 * @LastEditors: wenbin
 * @LastEditTime: 2021-11-15 14:44:33
 * @FilePath: /vite-ts-vue3-test/src/store/modules/platform.ts
 * Copyright (C) 2021 wenbin. All rights reserved.
 */
import * as types from '../mutation-types';

export default {
  state: {
    menu: [],
  },
  getters: {
    menu: (state: any) => {
      return state.menu || window.localStorage.getItem('menu');
    },
  },
  mutations: {
    [types.SET_MENU_LIST](state: any, datas: any) {
      state.menu = datas;
    },
  },
  actions: {
    [types.GET_MENU_LIST](context: any, magusUI: any) {
      return new Promise((resolve, reject) => {
        magusUI.apiConfig
          .get('/magustest/menu')
          .then((res: any) => {
            magusUI.catchUtil.setLocalItem('menu', JSON.stringify(res.data));
            context.commit('SET_MENU_LIST', res.data);
            resolve(res);
          })
          .catch((err: any) => {
            reject(err);
          });
      });
    },
  },
};
